package com.cloudsea.yunhaianalysis.controller;

import com.cloudsea.yunhaianalysis.service.ForecastService;
import com.cloudsea.yunhaianalysis.vo.ForecastVO;
import com.cloudsea.yunhaiutils.common.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.time.LocalDate;

@Tag(name = "商家-智能预测", description = "为商家提供备餐、运营等方面的智能预测与建议")
@RestController
@RequestMapping("/forecast")
public class ForecastController {

    @Autowired
    private ForecastService forecastService;

    @Operation(summary = "获取备餐建议报告", description = "根据目标日期，结合历史数据、天气、节假日等因素，生成核心单品的备货建议")
    @GetMapping("/preparation")
    public ApiResponse<ForecastVO> getPreparationForecast(
            @Parameter(description = "门店ID", required = true) @RequestParam Long storeId,
            @Parameter(description = "目标预测日期 (格式: yyyy-MM-dd)", required = true)
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate targetDate
    ) {
        // 【权限校验】应在此处添加校验，确保用户有权查询该storeId

        ForecastVO forecast = forecastService.generateForecast(storeId, targetDate);
        return ApiResponse.success(forecast);
    }
}
